package com.xzy.order_service.service.impl;

import com.fasterxml.jackson.databind.JsonNode;
import com.xzy.order_service.service.OrderClient;
import com.xzy.order_service.service.OrderService;
import com.xzy.order_service.utils.JsonUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.Map;

@Service
public class OrderServiceImpl implements OrderService {

    @Autowired
    private RestTemplate restTemplate;
    private final Logger log= LoggerFactory.getLogger(getClass());


    @Autowired
    private OrderClient orderClient;

    @Override
    public Object save(int userId, int productId) {
        log.info("order-service save");
        //ribbon方式
        Map<String,Object> bean = restTemplate.getForObject("http://PRODUCT-SERVICE/api/v1/product/findById?id="+productId, Map.class);
        //feign方式
        String byId = orderClient.findById(productId);
        JsonNode jsonNode = JsonUtils.str2JsonNode(byId);
        //int price = Integer.parseInt(jsonNode.get("price").toString());
//        ProductOrder productOrder=new ProductOrder();
//        productOrder.setCreateTime(new Date());
//        productOrder.setId(1);
//        productOrder.setTradeNo(UUID.randomUUID().toString());
//        productOrder.setUserId(userId);


        return bean;
    }
}
